using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
//
// DotNetNuke- http://www.dotnetnuke.com
// Copyright (c) 2002-2010
// by DotNetNuke Corporation
//

using System.Data.SqlClient;
using DotNetNuke.Common;
using Microsoft.ApplicationBlocks.Data;

namespace DotNetNuke.Modules.Html
{

    public partial class SqlDataProvider : DataProvider
    {

        #region "Public Methods"

        public override int AddWorkflow(int PortalID, string WorkflowName, string Description, bool IsDeleted)
        {
            return Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner + ObjectQualifier + "AddWorkflow", GetNull(PortalID), WorkflowName, Description, IsDeleted));
        }

        public override int AddWorkflowState(int WorkflowID, string StateName, int Order, bool Notify, bool IsActive)
        {
            return Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner + ObjectQualifier + "AddWorkflowState", WorkflowID, StateName, Order, Notify, IsActive));
        }

        public override bool CanDeleteWorkFlowState(int StateID)
        {
            return Convert.ToBoolean(SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner + ObjectQualifier + "CanDeleteWorkFlowState", StateID));
        }

        public override void DeleteWorkflowState(int StateID)
        {
            SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner + ObjectQualifier + "DeleteWorkflowState", StateID);
        }

        public override IDataReader GetWorkflow(int WorkflowID)
        {
            return (IDataReader)SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "GetWorkflow", WorkflowID);
        }

        public override IDataReader GetWorkflowState(int StateID)
        {
            return (IDataReader)SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "GetWorkflowState", StateID);
        }

        public override void UpdateWorkflow(int WorkflowID, string WorkflowName, string Description, bool IsDeleted)
        {
            SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner + ObjectQualifier + "UpdateWorkflow", WorkflowID, WorkflowName, Description, IsDeleted);
        }

        public override void UpdateWorkflowState(int StateID, string StateName, int Order, bool Notify, bool IsActive)
        {
            SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner + ObjectQualifier + "UpdateWorkflowState", StateID, StateName, Order, Notify, IsActive);
        }

        private object GetRoleNull(int RoleID)
        {
            if (RoleID.ToString() == DotNetNuke.Common.Globals.glbRoleNothing)
            {
                return DBNull.Value;
            }
            else
            {
                return RoleID;
            }
        }

        public override IDataReader GetPermissionsByStateID(int StateID)
        {
            return (IDataReader)SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "GetPermissionsByStateID", StateID);
        }

        public override IDataReader GetWorkflowStatePermission(int WorkflowStatePermissionID)
        {
            return (IDataReader)SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "GetWorkflowStatePermission", WorkflowStatePermissionID);
        }

        public override void DeleteWorkflowStatePermissionsByStateID(int StateID)
        {
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "DeleteWorkflowStatePermissionsByStateID", StateID);
        }

        public override void DeleteWorkflowStatePermissionsByUserID(int userID)
        {
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "DeleteWorkflowStatePermissionsByUserID", userID);
        }

        public override void DeleteWorkflowStatePermission(int WorkflowStatePermissionID)
        {
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "DeleteWorkflowStatePermission", WorkflowStatePermissionID);
        }

        public override int AddWorkflowStatePermission(int stateID, int permissionID, int roleID, bool allowAccess, int userID, int createdByUserID)
        {
            return Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner + ObjectQualifier + "AddWorkflowStatePermission", stateID, permissionID, GetRoleNull(roleID), allowAccess, GetNull(userID), createdByUserID));
        }

        public override void UpdateWorkflowStatePermission(int WorkflowStatePermissionID, int portalWorkflowStateID, int permissionID, int roleID, bool allowAccess, int userID, int lastModifiedByUserID)
        {
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "UpdateWorkflowStatePermission", WorkflowStatePermissionID, portalWorkflowStateID, permissionID, GetRoleNull(roleID), allowAccess, GetNull(userID), lastModifiedByUserID);
        }

        #endregion

    }

}
